<?php


namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Models\Tcmclassic;
use App\Models\TcmFoodDetail;
use App\Models\TcmMedicineddietDetail;
use App\Models\TcmDrugDetail;
use App\Models\TcmPrescriptionDetail;
use App\Models\TcmMedicineDetail;
use App\Models\TcmDongqipointDetail;
use App\Models\TcmCaseDetail;
use App\Models\TcmDoctorDetail;
use App\Models\TcmTeaDetail;

class AddtcmController extends Controller
{
    /**
     * 主导航
     * @return Array
     */
    public function main_nav()
	{
		$list = Tcmclassic::query()
		        ->where(['status'=>1])
				->orderBy('sort', 'desc')
				->select('id','name','images','url')
				->get();
        return response()->json($list);		
	}
	
	/**
     * 食材
     * @return Array
     */
    public function tcm_class(Request $request)
	{
		$name = $request->input('name') ?? '';
		$modules = $request->input('modules') ?? 'tea';
		switch($modules){
			case 'food':
			   $query = TcmFoodDetail::query();
			break;
			case 'medicineddiet':
			   $query = TcmMedicineddietDetail::query();
			break;
			case 'drug':
			   $query = TcmDrugDetail::query();
			break;
			case 'prescription':
			   $query = TcmPrescriptionDetail::query();
			break;
			case 'medicine':
			   $query = TcmMedicineDetail::query();
			break;
			case 'dongqipoint':
			   $query = TcmDongqipointDetail::query();
			break;
			case 'case':
			   $query = TcmCaseDetail::query();
			break;
			case 'doctor':
			   $query = TcmDoctorDetail::query();
			break;
			case 'tea':
			   $query = TcmTeaDetail::query();
			break;
		}
		if(empty($query)){
			return response()->json([]);	
		}
		if($name){
			$query->where('name', 'like', '%' . $name . '%');
		}
		$list = $query->orderBy('id', 'asc')->paginate();	
        return response()->json($list);			
	}
}
